﻿Shader "Learning/RenderPassShader1"
{
    Properties
    {
        _MainTex("MainTex" , 2D) = "white"{} // 注意必须使用_MainTex属性名，图像才能正常渲染回摄像机上
    }
    SubShader
    {
        Tags { "RenderPipeline"="UniversalPipeline" }

        Pass
        {
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            struct Attributes
            {
                float4 positionOS   : POSITION;
                float2 texcoord     : TEXCOORD;
            };
            struct Varyings
            {
                float4 positionHCS  : SV_POSITION;
                float2 uv           : TEXCOORD;
            };

            TEXTURE2D(_MainTex);
            SAMPLER(sampler_MainTex);

            CBUFFER_START(UnityPerMaterial)
                float4 _MainTex_ST;
            CBUFFER_END
           
            Varyings vert (Attributes v)
            {
                Varyings o=(Varyings)0;
                
                o.positionHCS = TransformObjectToHClip(v.positionOS.xyz);
                o.uv = TRANSFORM_TEX(v.texcoord , _MainTex);

                return o;
            }

            float4 frag (Varyings i) : SV_Target
            {
                float4 baseMap = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex , i.uv);

                // 置灰
                float gray = dot(baseMap.rgb, float3(0.299, 0.587, 0.114));
                return half4(gray, gray, gray, baseMap.a);
                
                // return baseMap * _Color;
            }
            ENDHLSL
        }
    }
}
